package com.example.hm_dtfkz.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import androidx.viewbinding.ViewBinding;

import com.android.base.ui.base.VBBaseActivity;
import com.android.base.util.DQLog;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.databinding.ActivityWithdrawalRecordBinding;
import com.example.hm_dtfkz.entity.QAWithdrawRecord;
import com.example.hm_dtfkz.ui.adapter.WithdrawalRecordAdapter;

import java.util.List;

/**
 * FileName: WithdrawalRecordActivity
 * Author: admin
 * Date: 2021/11/4 17:08
 * Description:
 */
public class WithdrawalRecordActivity extends VBBaseActivity implements View.OnClickListener {

    private ActivityWithdrawalRecordBinding recordBinding;
    private WithdrawalRecordAdapter recordAdapter;

    public static void startActivity(Activity activity) {
        Intent intent = new Intent(activity, WithdrawalRecordActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected ViewBinding getViewBinding() {
        setTitleBackground(BG_WHITE);
        return recordBinding = ActivityWithdrawalRecordBinding.inflate(getLayoutInflater());
    }

    @Override
    public void initView() {
        super.initView();
        recordBinding.tvTitle.setText("提现记录");
        recordAdapter = new WithdrawalRecordAdapter();
        recordBinding.recyclerView.setAdapter(recordAdapter);
    }

    @Override
    public void initData() {
        super.initData();
        getRecordData();
    }

    private void getRecordData() {
//        HXCurrencySDK.getInstance().getQAWithdrawRecord(new HttpUtil.HttpUtilCallback() {
//            @Override
//            public void onSuccess(int i, String s) {
//                DQLog.e("获取提现记录成功：" + s);
//                QAWithdrawRecordResp qaWithdrawRecordResp = JsonUtil.parseObject(s, QAWithdrawRecordResp.class);
//                if (qaWithdrawRecordResp != null && qaWithdrawRecordResp.getErrorCode() == 0) {
//                    updateUI(qaWithdrawRecordResp.getWrvl());
//                } else {
//                    updateUI(null);
//                }
//            }
//
//            @Override
//            public void onFailed(int i, Throwable throwable) {
//                DQLog.e("获取提现记录失败：" + throwable.getMessage());
//                updateUI(null);
//            }
//        });
    }

    private void updateUI(List<QAWithdrawRecord> list) {
        if (list != null && list.size() > 0) {
            recordAdapter.setList(list);
            recordAdapter.notifyDataSetChanged();
            recordBinding.recyclerView.setVisibility(View.VISIBLE);
            recordBinding.tvNoData.setVisibility(View.GONE);
        } else {
            recordBinding.recyclerView.setVisibility(View.GONE);
            recordBinding.tvNoData.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void initLister() {
        super.initLister();
        recordBinding.imgBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.imgBack) {
            finish();
        }
    }
}
